using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Entities;
using Utility;
using System.Text;

public partial class Admin_SanPham_DanhSachTinhTrangDel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {

        Pager_TinhTrangDel.PageSize = 5;
        Criteria c = new Criteria();
        if (txt_TenTinhTrangDel.Text != "")
        {
            c.add(Condition.AND, tbTinhTrangDealColumns.TenTT, Condition.LIKE,
                txt_TenTinhTrangDel.Text);
        }
        int total = 0;
        tbTinhTrangDealCollection tinhtrangdelCollection = tbTinhTrangDealBUS.Get(c.Criter, Pager_TinhTrangDel.CurrentIndex, Pager_TinhTrangDel.PageSize,
            tbTinhTrangDealColumns.MaTT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = tinhtrangdelCollection;
        Repeater1.DataBind();

        Pager_TinhTrangDel.ItemCount = total;
        if (total <= Pager_TinhTrangDel.PageSize)
            Pager_TinhTrangDel.Visible = false;
    }  
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
             e.Item.ItemType == ListItemType.Item)
        {
            tbTinhTrangDeal tinhtrangdel = (tbTinhTrangDeal)e.Item.DataItem;

            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "~/Admin/SanPham/CapNhatTinhTrangDel.aspx?id=" + tinhtrangdel.MaTT.ToString();
        }
    }
    protected void lbt_Xoa_Click1(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbTinhTrangDealBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
    protected void Pager_TinhTrangDel_Command(object sender, CommandEventArgs e)
    {
        Pager_TinhTrangDel.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
 
}
